package com.youbug.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youbug.system.entity.Announcement;
import com.youbug.system.mapper.AnnouncementMapper;
import com.youbug.system.service.IAnnouncementService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youbug.system.vo.AnnouncementVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 公告信息表 服务实现类
 * </p>
 *
 * @author youbug
 * @since 2023-04-11
 */
@Service
public class AnnouncementServiceImpl extends ServiceImpl<AnnouncementMapper, Announcement> implements IAnnouncementService {

    @Override
    public IPage<Announcement> getAnnouncementPage(AnnouncementVo vo) {

        Page<Announcement> ansmtPage = new Page<>();

        ansmtPage.setCurrent(vo.getCurrentPage());

        ansmtPage.setSize(vo.getPageSize());

        QueryWrapper<Announcement> wrapper = new QueryWrapper<>();

        if(StringUtils.hasText(vo.getContent())){

            wrapper.like("content", vo.getContent());
        }

        if(StringUtils.hasText(vo.getType())){

            wrapper.eq("type", vo.getType());
        }

        if(vo.getValid() != null){

            wrapper.eq("valid", vo.getValid());
        }

        Page<Announcement> page = this.page(ansmtPage, wrapper);

        return page;
    }
}
